Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support unnamed prepared statements #635

Merged
merged 7 commits into from
Nov 9, 2023

Conversation

sjuls
Copy link
Contributor

@sjuls sjuls commented Nov 7, 2023

This PR fixes a minor issue we've encountered when using the standard golang postgres driver. It uses unnamed prepared statements to do one-off parameterized queries via QueryContext - these are often failing with could not query: pq: unnamed prepared statement does not exist errors.

The current logic effectively results in unnamed prepared statements being 'disabled' - they do not get cached and pre-prepared on bind and therefore fail if PARSE and BIND are distributed across two different servers.

PR includes;

  • Added golang test suite to reproduce the issue
  • Implemented fix to allow caching of unnamed prepared statements

@sjuls
Copy link
Contributor Author

sjuls commented Nov 7, 2023

Hm, this breaks the ruby prepared statement tests - missed that locally 🤦

@sjuls sjuls force-pushed the unnamed-prepared-statements branch from 1fe6f24 to c3a1ce5 Compare November 7, 2023 14:06
@sjuls
Copy link
Contributor Author

sjuls commented Nov 7, 2023

Hi @levkk,

What's the procedure to update the pgcat-ci container image? I would like to install golang to run the golang test-suite in this PR to validate prepared statements work with the golang pg driver 🙏

Should I make a separate PR for updating the docker files?

@levkk
Copy link
Contributor

levkk commented Nov 7, 2023

Hi @levkk,

What's the procedure to update the pgcat-ci container image? I would like to install golang to run the golang test-suite in this PR to validate prepared statements work with the golang pg driver 🙏

Should I make a separate PR for updating the docker files?

Hello. I think you can just install golang in CI, we use Circle. If needed, you could also make a separate PR.

@sjuls
Copy link
Contributor Author

sjuls commented Nov 7, 2023

Yeah, just seems like circle pulls pgcat-ci:latest, doesn't build the Dockerfile.ci on the branch. I'll make a separate PR to get the pgcat-ci:latest loaded with golang.

Thanks!

@sjuls
Copy link
Contributor Author

sjuls commented Nov 8, 2023

Thank you for the merge of golang in pgcat-ci, @levkk - Looks like the tests are passing now.

Let me know what you think of this PR, and whether there is anything I'm overlooking. I've deployed a build of this branch on our internal test setup and our queries are now going through.

@levkk levkk merged commit 7c37da2 into postgresml:main Nov 9, 2023
1 check passed
@levkk
Copy link
Contributor

levkk commented Nov 9, 2023

Looks great, thank you!

@zainkabani
Copy link
Contributor

Want to call out the pgbouncer currently doesn't support caching unnamed statements like this so thank you for adding that!

@drdrsh
Copy link
Collaborator

drdrsh commented Sep 8, 2024

I think we will want to put this feature behind a config. Unnamed prepared statements are used by many clients to send regular (unprepared) queries to the database. They are typically sent in one burst of P->B->D->E->S packets. Treating this use case as named prepared statements would very quickly eat up the cache storage because we now treat any extended protocol query as a named prepared query.

Also, it will introduce unexpected new behavior, as we will now be using caching query plans for unnamed prepared statements and that may have negative performance consequences (unlikely but possible due to suboptimal cached plans)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants